#version 330 core

in vec3 oPos;
in vec2 oTexCoord;

out vec4 oFragColor;

uniform sampler2D uTexUnit;
uniform float uW;
uniform float uH;

vec4 originTexCol() {
    return texture(uTexUnit, oTexCoord);
}

void main() {
    // 手动计算mipmap级别
    vec2 uv = oTexCoord * vec2(uW, uH);
    vec2 dx = dFdx(uv);
    vec2 dy = dFdy(uv);
    float maxDetal = sqrt(max(dot(dx, dx), dot(dy, dy)));
    float L = log2(maxDetal);
    int level = max(int(L + 0.5), 0);
    oFragColor = textureLod(uTexUnit, oTexCoord, level);
}
